package ModelLayer;


import java.util.ArrayList;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class LoanRecordsTest.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class LoanRecordsTest
{
    /**
     * Default constructor for test class LoanRecordsTest
     */
    public LoanRecordsTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }
    
  
    @Test
    public void testCreateLoan()
    {
        DVD dvd = new DVD(1, "Dvd", "DMX", 156);
        DVDRecords.getInstance().addDVD(dvd);
        dvd.createCopy(1, 15, 15);
        Person person = new Person(1, "Ivcho", "Otsreshta", 1517, "Sofia", 12); 
        AddressBook.getInstance().addPerson(person);
        LoanRecords.getInstance().createLoan(1, 1, 1, 1, 1, 135);
        assertNotNull(LoanRecords.getInstance().getLoan(1));
    }
    
    @Test
    public void testRemoveLoan()
    {
        DVD dvd = new DVD(0, "Dvd", "DMX", 156);
        DVDRecords.getInstance().addDVD(dvd);
        Copy copy = new Copy(0, 15, 15, dvd);
        Person person = new Person(0, "Ivcho", "Otsreshta", 1517, "Sofia", 12); 
        Loan loan = new Loan(0,0,0,0,0,0,"hi"); 
        boolean status = false;
        LoanRecords.getInstance().addLoan(loan);
        LoanRecords.getInstance().removeLoan(0);
        assertNotNull(LoanRecords.getInstance().getLoan(0));
    }
    
    
    @Test
    public void testGetLoan()
    {
        DVD dvd = new DVD(0, "Dvd", "DMX", 156);
        DVDRecords.getInstance().addDVD(dvd);
        Copy copy = new Copy(0, 15, 15, dvd);
        Person person = new Person(0, "Ivcho", "Otsreshta", 1517, "Sofia", 12); 
        Loan loan = new Loan(0,0,0,0,0,0,"hi");  
        LoanRecords.getInstance().addLoan(loan);        
        assertNotNull(LoanRecords.getInstance().getLoan(0));
    }
    
    
    @Test 
    public void testUpdateLoan()
    {
        DVD dvd = new DVD(0, "Dvd", "DMX", 156);
        DVDRecords.getInstance().addDVD(dvd);
        Copy copy = new Copy(0, 15, 15, dvd);
        Person person = new Person(0, "Ivcho", "Otsreshta", 1517, "Sofia", 12); 
        Loan loan = new Loan(0,0,0,0,0,0,"hi");  
        LoanRecords.getInstance().addLoan(loan);
        LoanRecords.getInstance().updateLoan(1,0,"4");
        assertEquals(4, LoanRecords.getInstance().getLoan(0).getBorrowDate());
    }
    
    
    @Test
    public void testAddLoan()
    {
        DVD dvd = new DVD(0, "Dvd", "DMX", 156);
        DVDRecords.getInstance().addDVD(dvd);
        Copy copy = new Copy(0, 15, 15, dvd);
        Person person = new Person(0, "Ivcho", "Otsreshta", 1517, "Sofia", 12); 
        Loan loan = new Loan(0,0,0,0,0,0,"hi");  
        boolean status = false;
        LoanRecords.getInstance().addLoan(loan);
        ArrayList<Loan> loans = LoanRecords.getInstance().getLoansList();
        for (Loan curLoan : loans)
        {
            if (curLoan==loan) status = true;
        }
        assertTrue(status);
    }    
 }
    
    
    

